<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title> - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content=" - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/springboot2.x-%E9%9B%86%E6%88%90-jedis%E5%92%8Cspring-boot-starter-data-redis%E7%9A%84%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E6%AF%94%E8%BE%83jedis%E5%AE%8C%E8%83%9C%E9%99%84%E5%B8%A6%E6%BA%90%E7%A0%81/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1636 字 ~8分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<blockquote>
<blockquote>
<p>文章系转载，方便整理和归纳</p>

<p>版权声明：本文为CSDN博主「斌哥谈编程」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：<a href="https://blog.csdn.net/houpeibin2012/article/details/105839651">https://blog.csdn.net/houpeibin2012/article/details/105839651</a></p>
</blockquote>

<p><a href="#r1">1.pom文件引入jedis和spring-boot-starter-data-redis的依赖</a>
<a href="#r2">2.其他依赖的引入（Swagger）</a>
<a href="#r3">3.Jedis配置类</a>
<a href="#r4">4.Jedis及spring-boot-starter-data-redis的配置信息</a>
<a href="#r5">5.Swagger配置类</a>
<a href="#r6">6.编写测试相关类</a>
<a href="#r7">7.测试</a>
<a href="#r7-1">7.1插入数据测试</a>
<a href="#r7-2">7.2读取数据测试</a>
<a href="#r7-3">7.3多线程读取数据测试</a>
<a href="#r8">8. 结论</a></p>

<p>温馨提示：
本文配套代码：<a href="https://gitee.com/guduwuhen/springboot2-lesson/tree/master/redispro">https://gitee.com/guduwuhen/springboot2-lesson/tree/master/redispro</a></p>

<h3 id="1-pom文件引入jedis和spring-boot-starter-data-redis的依赖-span-id-r1-span">1.pom文件引入jedis和spring-boot-starter-data-redis的依赖 <span id=r1></span></h3>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-xml" data-lang="xml"><span style="color:#204a87;font-weight:bold">&lt;properties</span><span style="color:#204a87;font-weight:bold">&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;java.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>1.8<span style="color:#204a87;font-weight:bold">&lt;/java.version&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;jedis.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>2.9.0<span style="color:#204a87;font-weight:bold">&lt;/jedis.version&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;fastjson.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>1.2.68<span style="color:#204a87;font-weight:bold">&lt;/fastjson.version&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;guava.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>28.2-jre<span style="color:#204a87;font-weight:bold">&lt;/guava.version&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;/properties&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>redis.clients<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>jedis<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>${jedis.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter-data-redis<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span></code></pre></div>
<p>Springboot 使用的是2.2.4.RELEASE版本。</p>

<h3 id="2-其他依赖的引入-swagger-span-id-r2-span">2.其他依赖的引入（Swagger） <span id=r2></span></h3>

<p>如下是完整的pom文件代码：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-xml" data-lang="xml"><span style="color:#8f5902;font-style:italic">&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;</span>
<span style="color:#204a87;font-weight:bold">&lt;project</span> <span style="color:#c4a000">xmlns=</span><span style="color:#4e9a06">&#34;http://maven.apache.org/POM/4.0.0&#34;</span> <span style="color:#c4a000">xmlns:xsi=</span><span style="color:#4e9a06">&#34;http://www.w3.org/2001/XMLSchema-instance&#34;</span>
         <span style="color:#c4a000">xsi:schemaLocation=</span><span style="color:#4e9a06">&#34;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&#34;</span><span style="color:#204a87;font-weight:bold">&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;modelVersion</span><span style="color:#204a87;font-weight:bold">&gt;</span>4.0.0<span style="color:#204a87;font-weight:bold">&lt;/modelVersion&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;parent</span><span style="color:#204a87;font-weight:bold">&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter-parent<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>2.2.4.RELEASE<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;relativePath</span><span style="color:#204a87;font-weight:bold">/&gt;</span> <span style="color:#8f5902;font-style:italic">&lt;!--</span><span style="color:#8f5902;font-style:italic"> lookup parent from repository </span><span style="color:#8f5902;font-style:italic">--&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;/parent&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>com.ieslab.powergrid<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>redispro<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>0.0.1-SNAPSHOT<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;name</span><span style="color:#204a87;font-weight:bold">&gt;</span>demosvr<span style="color:#204a87;font-weight:bold">&lt;/name&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;description</span><span style="color:#204a87;font-weight:bold">&gt;</span>Demo project for Spring Boot<span style="color:#204a87;font-weight:bold">&lt;/description&gt;</span>

    <span style="color:#204a87;font-weight:bold">&lt;properties</span><span style="color:#204a87;font-weight:bold">&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;java.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>1.8<span style="color:#204a87;font-weight:bold">&lt;/java.version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;jedis.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>2.9.0<span style="color:#204a87;font-weight:bold">&lt;/jedis.version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;fastjson.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>1.2.68<span style="color:#204a87;font-weight:bold">&lt;/fastjson.version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;guava.version</span><span style="color:#204a87;font-weight:bold">&gt;</span>28.2-jre<span style="color:#204a87;font-weight:bold">&lt;/guava.version&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;/properties&gt;</span>

    <span style="color:#204a87;font-weight:bold">&lt;dependencies</span><span style="color:#204a87;font-weight:bold">&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter-web<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>

        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>redis.clients<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>jedis<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>${jedis.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter-data-redis<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>

        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>io.springfox<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>springfox-swagger2<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>2.9.2<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>io.springfox<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>springfox-swagger-ui<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>2.9.2<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>com.google.guava<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>guava<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>${guava.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>com.alibaba<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>fastjson<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;version</span><span style="color:#204a87;font-weight:bold">&gt;</span>${fastjson.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>


        <span style="color:#8f5902;font-style:italic">&lt;!--</span><span style="color:#8f5902;font-style:italic"> 热部署时使用 </span><span style="color:#8f5902;font-style:italic">--&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-devtools<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#8f5902;font-style:italic">&lt;!--</span><span style="color:#8f5902;font-style:italic"> set/get方法免写，需要安装idea的插件 </span><span style="color:#8f5902;font-style:italic">--&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.projectlombok<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>lombok<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;optional</span><span style="color:#204a87;font-weight:bold">&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/optional&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#8f5902;font-style:italic">&lt;!--</span><span style="color:#8f5902;font-style:italic">单元测试</span><span style="color:#8f5902;font-style:italic">--&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-starter-test<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;scope</span><span style="color:#204a87;font-weight:bold">&gt;</span>test<span style="color:#204a87;font-weight:bold">&lt;/scope&gt;</span>

        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;dependency</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.junit.platform<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>junit-platform-launcher<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;scope</span><span style="color:#204a87;font-weight:bold">&gt;</span>test<span style="color:#204a87;font-weight:bold">&lt;/scope&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;/dependencies&gt;</span>

    <span style="color:#204a87;font-weight:bold">&lt;build</span><span style="color:#204a87;font-weight:bold">&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;plugins</span><span style="color:#204a87;font-weight:bold">&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;plugin</span><span style="color:#204a87;font-weight:bold">&gt;</span>
                <span style="color:#204a87;font-weight:bold">&lt;groupId</span><span style="color:#204a87;font-weight:bold">&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
                <span style="color:#204a87;font-weight:bold">&lt;artifactId</span><span style="color:#204a87;font-weight:bold">&gt;</span>spring-boot-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
            <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
        <span style="color:#204a87;font-weight:bold">&lt;/plugins&gt;</span>
    <span style="color:#204a87;font-weight:bold">&lt;/build&gt;</span>

<span style="color:#204a87;font-weight:bold">&lt;/project&gt;</span></code></pre></div>
<h3 id="3-jedis配置类-span-id-r3-span">3.Jedis配置类 <span id=r3></span></h3>

<p>RedisConfiguration.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.config</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.beans.factory.annotation.Autowired</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.beans.factory.annotation.Qualifier</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.beans.factory.annotation.Value</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Bean</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Configuration</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.JedisPool</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.JedisPoolConfig</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: RedisConfiguration &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: 用户rest接口类，测试demo使用&lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author binge
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#5c35cc;font-weight:bold">@Configuration</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">RedisConfiguration</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;jedis.pool&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@Autowired</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">JedisPool</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@Qualifier</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;jedis.pool.config&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">JedisPoolConfig</span> <span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">,</span>
                               <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${jedis.pool.host}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000">String</span> <span style="color:#000">host</span><span style="color:#ce5c00;font-weight:bold">,</span>
                               <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${jedis.pool.port}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">port</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">JedisPool</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">host</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">port</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;jedis.pool.config&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">JedisPoolConfig</span> <span style="color:#000">jedisPoolConfig</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${jedis.pool.config.maxTotal}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">maxTotal</span><span style="color:#ce5c00;font-weight:bold">,</span>
                                            <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${jedis.pool.config.maxIdle}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">maxIdle</span><span style="color:#ce5c00;font-weight:bold">,</span>
                                            <span style="color:#5c35cc;font-weight:bold">@Value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;${jedis.pool.config.maxWaitMillis}&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">maxWaitMillis</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">JedisPoolConfig</span> <span style="color:#000">config</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">JedisPoolConfig</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMaxTotal</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">maxTotal</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMaxIdle</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">maxIdle</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMaxWaitMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">maxWaitMillis</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">config</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<h3 id="4-jedis及spring-boot-starter-data-redis的配置信息-span-id-r4-span">4. Jedis及spring-boot-starter-data-redis的配置信息 <span id=r4></span></h3>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">spring</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">redis</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#8f5902;font-style:italic">#数据库索引</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">database</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">host</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">192.168</span><span style="color:#0000cf;font-weight:bold">.22</span><span style="color:#0000cf;font-weight:bold">.150</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">port</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">6379</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">lettuce</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">pool</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">#最大连接数</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">max-active</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">#最大阻塞等待时间(负数表示没限制)</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">max-wait</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">5000</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">#最大空闲</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">max-idle</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">500</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">#最小空闲</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">min-idle</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">8</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#8f5902;font-style:italic">#连接超时时间</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">timeout</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">10000</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">jedis </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">pool </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">host </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">192.168</span><span style="color:#0000cf;font-weight:bold">.22</span><span style="color:#0000cf;font-weight:bold">.150</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">port </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">6379</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">config </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">maxTotal</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">maxIdle</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">maxWaitMillis </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">100000</span></code></pre></div>
<h3 id="5-swagger配置类-span-id-r5-span">5. Swagger配置类 <span id=r5></span></h3>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.config</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Bean</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Configuration</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.builders.ApiInfoBuilder</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.builders.PathSelectors</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.builders.RequestHandlerSelectors</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.service.ApiInfo</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.service.Contact</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.spi.DocumentationType</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.spring.web.plugins.Docket</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">springfox.documentation.swagger2.annotations.EnableSwagger2</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: SwaggerConfig &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: Swagger配置类&lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author binge
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>

<span style="color:#5c35cc;font-weight:bold">@Configuration</span>
<span style="color:#5c35cc;font-weight:bold">@EnableSwagger2</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SwaggerConfig</span> <span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#5c35cc;font-weight:bold">@Bean</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Docket</span> <span style="color:#000">creatApi</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Docket</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">DocumentationType</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">SWAGGER_2</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">apiInfo</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">apiInfo</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span>   <span style="color:#8f5902;font-style:italic">// 指定构建api文档的详细信息的方法，下面会有实现：apiInfo()
</span><span style="color:#8f5902;font-style:italic"></span>                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">select</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#8f5902;font-style:italic">// 指定要生成api接口的包路径，这里把controller作为包路径，生成controller中的所有接口
</span><span style="color:#8f5902;font-style:italic"></span>                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">apis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">RequestHandlerSelectors</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">basePackage</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;com.test.redis.controller&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">paths</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">PathSelectors</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">any</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">build</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">ApiInfo</span> <span style="color:#000">apiInfo</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ApiInfoBuilder</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">title</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Spring Boot集成Swagger2接口测试&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">description</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;生成的接口如下&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">version</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;1.0&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">contact</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Contact</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;斌哥&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#4e9a06">&#34;https://blog.csdn.net/houpeibin2012&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#4e9a06">&#34;houpeibin@126.com&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span>
                <span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">build</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<h3 id="6-编写测试相关类-span-id-r6-span">6. 编写测试相关类 <span id=r6></span></h3>

<p>TestController.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.controller</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.test.redis.entity.Result</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.test.redis.entity.TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.test.redis.service.TestAsyncService</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">io.swagger.annotations.*</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">lombok.extern.slf4j.Slf4j</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.beans.factory.annotation.Autowired</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.dao.DataAccessException</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.data.redis.connection.StringRedisConnection</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.data.redis.core.*</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.RequestMapping</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.RequestParam</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.RestController</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.Jedis</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.JedisPool</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.Pipeline</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis.clients.jedis.Response</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.*</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.Map.Entry</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: TestController &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: 测试redis&lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author binge
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#5c35cc;font-weight:bold">@RestController</span>
<span style="color:#5c35cc;font-weight:bold">@Slf4j</span>
<span style="color:#5c35cc;font-weight:bold">@Api</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">tags</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;redis性能测试&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">TestController</span> <span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#5c35cc;font-weight:bold">@Autowired</span>
    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">JedisPool</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Autowired</span>
    <span style="color:#000">StringRedisTemplate</span> <span style="color:#000">redisTemplate</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#5c35cc;font-weight:bold">@Autowired</span>
    <span style="color:#000">TestAsyncService</span> <span style="color:#000">testAsyncService</span><span style="color:#ce5c00;font-weight:bold">;</span>


    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;del&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;删除所有库&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;删除所有库&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">del</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">flushAll</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;insertStringData&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;单个String数据插入&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;单个String数据插入&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiImplicitParams</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#5c35cc;font-weight:bold">@ApiImplicitParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;num&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">value</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;插入条数&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">dataType</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;Int&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">paramType</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;query&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span>
            <span style="color:#5c35cc;font-weight:bold">@ApiImplicitParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;type&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">value</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;数据类型&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">dataType</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">&#34;String&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">paramType</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;query&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#ce5c00;font-weight:bold">}</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">insertStringData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">set</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getTestStringData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;insertStringDataPipelined&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;jedis方式批量插入String数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;jedis方式批量插入String数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">insertStringDataPipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;num&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;插入条数&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">,</span>
                                            <span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;type&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;数据类型&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//使用管道方式，性能比单次获取性能高
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Pipeline</span> <span style="color:#000">pipeline</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">set</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getTestStringData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">valueOf</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;insertStringDataPipelinedByRedisTemplate&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;redisTemplate方式批量插入String数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;redisTemplate方式批量插入String数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">insertStringDataPipelinedByRedisTemplate</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;num&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;插入条数&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">,</span>
                                                          <span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;type&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;数据类型&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">/* 插入多条数据 */</span>
        <span style="color:#000">redisTemplate</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">executePipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">SessionCallback</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">Object</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#5c35cc;font-weight:bold">@Override</span>
            <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">K</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">V</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">Object</span> <span style="color:#000">execute</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">RedisOperations</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">K</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">V</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">redisOperations</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#204a87;font-weight:bold">throws</span> <span style="color:#000">DataAccessException</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">redisTemplate</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">opsForValue</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">set</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getTestStringData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
                <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#ce5c00;font-weight:bold">}</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getDataByKey&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key关键字获取所有key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key关键字获取所有key&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getDataByKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key关键字&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">keys</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">keys</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keys</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">log</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">info</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;.......keys:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">keys</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:数据个数：&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">keys</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getValueBykey&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getValueBykey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;过滤条件&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#8f5902;font-style:italic">//使用管道方式，性能比单次获取性能高
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">keys</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keys</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>

            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">ketTmp</span> <span style="color:#ce5c00;font-weight:bold">:</span><span style="color:#000">keys</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">String</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                    <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">haoshi</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;个数：&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;；耗时:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">haoshi</span><span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;；大小:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span>  <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>



    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getDataByPipelined&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据num,type过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据num,type过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getDataByPipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;num&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;查询条数&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">,</span>
                            <span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;type&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;数据类型&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#8f5902;font-style:italic">//使用管道方式，性能比单次获取性能高
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">Pipeline</span> <span style="color:#000">pipeline</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">TestDataEntity</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                    <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">valueOf</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">10</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Entry</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">entry</span> <span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">entrySet</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000">entry</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getValue</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#204a87;font-weight:bold">if</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">entry</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#4e9a06">&#34;-----&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
                <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:数据个数：&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getDataByPipelinedAndPipelineKey&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getDataByPipelinedAndPipelineKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;过滤条件&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#8f5902;font-style:italic">//使用管道方式，性能比单次获取性能高
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">Pipeline</span> <span style="color:#000">pipeline</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">keys</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keys</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sets</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">keys</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">ketTmp</span> <span style="color:#ce5c00;font-weight:bold">:</span><span style="color:#000">sets</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                    <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">haoshi</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;个数：&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;；耗时:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">haoshi</span><span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;；大小:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span>  <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getDataByPipelinedAndJedisKey&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getDataByPipelinedAndJedisKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;过滤条件&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">Jedis</span> <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">jedis</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#8f5902;font-style:italic">//使用管道方式，性能比单次获取性能高
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">Pipeline</span> <span style="color:#000">pipeline</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">pipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">map</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HashMap</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sets</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keys</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">ketTmp</span> <span style="color:#ce5c00;font-weight:bold">:</span><span style="color:#000">sets</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                    <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">catch</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">e</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">printStackTrace</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">pipeline</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">sync</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">sets</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">10</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Entry</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">entry</span> <span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">entrySet</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Response</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000">entry</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getValue</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#204a87;font-weight:bold">if</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">sets</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">entry</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#4e9a06">&#34;-----&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sResponse</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
                <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">map</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#000">jedis</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">close</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;getDataByPipelinedByRedisTemplate&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;RedisTemplate根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;RedisTemplate根据key过滤获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">getDataByPipelinedByRedisTemplate</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;过滤条件&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">try</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">Set</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">sets</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">jedisPool</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getResource</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">keys</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">keyList</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ArrayList</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">ketTmp</span> <span style="color:#ce5c00;font-weight:bold">:</span><span style="color:#000">sets</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">keyList</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">add</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ketTmp</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span>
            <span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">Object</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">obj</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">redisTemplate</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">executePipelined</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">RedisCallback</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">redisConnection</span> <span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                <span style="color:#000">StringRedisConnection</span> <span style="color:#000">stringRedisConnection</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">StringRedisConnection</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">redisConnection</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">keyTmp</span> <span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#000">keyList</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
                    <span style="color:#000">stringRedisConnection</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">keyTmp</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
                <span style="color:#ce5c00;font-weight:bold">}</span>
                <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#ce5c00;font-weight:bold">}</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
            <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">size</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getBytes</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">length</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#000">1024</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>

        <span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#204a87;font-weight:bold">finally</span> <span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#8f5902;font-style:italic">//返还到连接池
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;startAsyn&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#5c35cc;font-weight:bold">@ApiOperation</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;启动异步线程并发获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">notes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;启动异步线程并发获取数据&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">startAsyn</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;num&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;线程个数&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">,</span>
                            <span style="color:#5c35cc;font-weight:bold">@ApiParam</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;key&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">value</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;过滤条件&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">required</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#5c35cc;font-weight:bold">@RequestParam</span> <span style="color:#000">String</span> <span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">long</span> <span style="color:#000">startTime</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">num</span><span style="color:#ce5c00;font-weight:bold">;</span> <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">testAsyncService</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">startAsyn</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">key</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">currentTimeMillis</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#000">startTime</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>Result.java 返回结构</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.entity</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: PersonService &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: 通用Rest请求返回结构 &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author bingge
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">Result</span> <span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#8f5902;font-style:italic">//服务器返回的状态码(主要给程序员看)。例如 : 200 : 请求成功， 500 : 服务器内部错误，400 : 未知错误
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">Integer</span> <span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#8f5902;font-style:italic">//返回码 1：成功  10000：系统错误 10001：参数错误  ...
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">Integer</span> <span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#8f5902;font-style:italic">// 服务器的错误信息 ,主要返回给用户看
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">String</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#8f5902;font-style:italic">// 服务器返回的数据
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">private</span> <span style="color:#000">Object</span> <span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">;</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">null</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">ok</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Object</span> <span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">Result</span> <span style="color:#000">result</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setCode</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">200</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setStatus</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">1</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMsg</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;请求成功&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;请求失败&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Integer</span> <span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">Integer</span> <span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">String</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">Result</span> <span style="color:#000">result</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setCode</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setStatus</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMsg</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">result</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">500</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#8f5902;font-style:italic">//返回操作成功
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">Result</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ErrorStatus</span> <span style="color:#000">errorStatus</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">500</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">errorStatus</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">value</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">errorStatus</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getMessage</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Integer</span> <span style="color:#000">getCode</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">setCode</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Integer</span> <span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">this</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">code</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">code</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Integer</span> <span style="color:#000">getStatus</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">setStatus</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Integer</span> <span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">this</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">status</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">status</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">String</span> <span style="color:#000">getMsg</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">setMsg</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">this</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">msg</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">msg</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Object</span> <span style="color:#000">getData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">setData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Object</span> <span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">this</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">data</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>全局异常捕捉处理GlobleExceptionHandler.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.utils</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.test.redis.entity.MyException</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.test.redis.entity.Result</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.MissingServletRequestParameterException</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.ControllerAdvice</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.ExceptionHandler</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.web.bind.annotation.ResponseBody</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: GlobleExceptionHandler &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: 全局异常捕捉处理&lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author binge
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#5c35cc;font-weight:bold">@ControllerAdvice</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">GlobleExceptionHandler</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#5c35cc;font-weight:bold">@ResponseBody</span>
    <span style="color:#5c35cc;font-weight:bold">@ExceptionHandler</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">value</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">Exception</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Result</span> <span style="color:#000">errorHandler</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">Exception</span> <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#8f5902;font-style:italic">//判断异常的类型,返回不一样的返回值
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#204a87;font-weight:bold">if</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ex</span> <span style="color:#204a87;font-weight:bold">instanceof</span> <span style="color:#000">MissingServletRequestParameterException</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">400</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#4e9a06">&#34;全局异常捕捉：缺少必需参数：&#34;</span>
                    <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">MissingServletRequestParameterException</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#000">ex</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">getParameterName</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">else</span> <span style="color:#204a87;font-weight:bold">if</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">ex</span> <span style="color:#204a87;font-weight:bold">instanceof</span> <span style="color:#000">MyException</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
           <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">400</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#4e9a06">&#34;全局异常捕捉：这是自定义异常&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">Result</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">error</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">400</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#4e9a06">&#34;全局异常捕捉：未知异常&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>线程池配置AsyncConfiguration.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.config</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Bean</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.context.annotation.Configuration</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.scheduling.annotation.EnableAsync</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.concurrent.Executor</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/** &lt;p&gt;Title: PersonService &lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> * &lt;p&gt;Description: 线程池配置&lt;/p&gt;
</span><span style="color:#8f5902;font-style:italic"> *
</span><span style="color:#8f5902;font-style:italic"> * @author houpeibin
</span><span style="color:#8f5902;font-style:italic"> * @date 2020-2-20 下午7:15:30
</span><span style="color:#8f5902;font-style:italic"> * @version V1.0
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#5c35cc;font-weight:bold">@Configuration</span>
<span style="color:#5c35cc;font-weight:bold">@EnableAsync</span>  <span style="color:#8f5902;font-style:italic">// 启用异步任务
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">AsyncConfiguration</span> <span style="color:#ce5c00;font-weight:bold">{</span>

    <span style="color:#8f5902;font-style:italic">// 声明一个线程池(并指定线程池的名字)
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;taskExecutor&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#000">Executor</span> <span style="color:#000">asyncExecutor</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">ThreadPoolTaskExecutor</span> <span style="color:#000">executor</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">ThreadPoolTaskExecutor</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//核心线程数5：线程池创建时候初始化的线程数
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setCorePoolSize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">50</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//最大线程数5：线程池最大的线程数，只有在缓冲队列满了之后才会申请超过核心线程数的线程
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setMaxPoolSize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">500</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//缓冲队列500：用来缓冲执行任务的队列
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setQueueCapacity</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">500</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//允许线程的空闲时间60秒：当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setKeepAliveSeconds</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">60</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#8f5902;font-style:italic">//线程池名的前缀：设置好了之后可以方便我们定位处理任务所在的线程池
</span><span style="color:#8f5902;font-style:italic"></span>        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">setThreadNamePrefix</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;DailyAsync-&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">initialize</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">executor</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<p>TestDataEntity.java</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">package</span> <span style="color:#000">com.test.redis.entity</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">com.alibaba.fastjson.JSONObject</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.UUID</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#8f5902;font-style:italic">/**
</span><span style="color:#8f5902;font-style:italic"> * 测试数据类
</span><span style="color:#8f5902;font-style:italic"> */</span>
<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">TestDataEntity</span> <span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">String</span> <span style="color:#000">testStringData</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#204a87;font-weight:bold">static</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">StringBuffer</span> <span style="color:#000">sb</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">StringBuffer</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">for</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">0</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">100</span><span style="color:#ce5c00;font-weight:bold">;</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">i</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
            <span style="color:#000">sb</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">append</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;测试&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#ce5c00;font-weight:bold">}</span>
        <span style="color:#000">testStringData</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">sb</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">String</span> <span style="color:#000">getTestStringData</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">JSONObject</span> <span style="color:#000">obj</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">JSONObject</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;type&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;uuid&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">UUID</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">randomUUID</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">put</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;data&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span><span style="color:#000">testStringData</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">obj</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">toString</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>

    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#000">String</span> <span style="color:#000">getKey</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">index</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">String</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#4e9a06">&#34;rtd:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">index</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#4e9a06">&#34;:&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">;</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span></code></pre></div>
<h3 id="7-测试-span-id-r7-span">7. 测试 <span id=r7></span></h3>

<p>打开<a href="http://localhost:8080/swagger-ui.html#/">http://localhost:8080/swagger-ui.html#/</a></p>

<h4 id="7-1-插入数据测试-span-id-r7-1-span">7.1 插入数据测试 <span id=r7-1></span></h4>

<p>首先从<a href="http://localhost:8080/swagger-ui.html#/">http://localhost:8080/swagger-ui.html#/</a> 测试界面中，找到“单个String数据插入”接口：/insertStringData</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192145.png" width = 600 /> </div>

<p>点击“Try it out”，</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192222.png" width = 600 /> </div>

<p>执行结果在图形的下面，如下图</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192237.png" width = 600 /> </div>

<p>依照此方法依次测试insertStringDataPipelined和insertStringDataPipelinedByRedisTemplate接口</p>

<p><strong>单位：ms</strong></p>

<table>
<thead>
<tr>
<th>个数</th>
<th>jedis单次写入</th>
<th>jedis批量写入</th>
<th>RedisTemplate批量写入</th>
</tr>
</thead>

<tbody>
<tr>
<td>3000个</td>
<td>192</td>
<td>28</td>
<td>54</td>
</tr>

<tr>
<td>30000个</td>
<td>2432</td>
<td>242</td>
<td>539</td>
</tr>

<tr>
<td>100000个</td>
<td>6061</td>
<td>762</td>
<td>1988</td>
</tr>

<tr>
<td>300000个</td>
<td>19203</td>
<td>2262</td>
<td>7015</td>
</tr>
</tbody>
</table>

<p>一个数据的长度为：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-json" data-lang="json"><span style="color:#000;font-weight:bold">{</span><span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#204a87;font-weight:bold">&#34;type&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#204a87;font-weight:bold">&#34;uuid&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;aa5b34ba-dd43-4d93-a795-485a0683be7a&#34;</span><span style="color:#000;font-weight:bold">}</span></code></pre></div>
<h4 id="7-2-读取数据测试-span-id-r7-2-span">7.2 读取数据测试 <span id=r7-2></span></h4>

<p>依照此方法依次测试getValueBykey 和getDataByPipelinedAndPipelineKey 、getDataByPipelinedByRedisTemplate接口</p>

<p><strong>单位：ms</strong></p>

<table>
<thead>
<tr>
<th>个数</th>
<th>jedis单次读取</th>
<th>jedis批量读取</th>
<th>RedisTemplate批量读取</th>
</tr>
</thead>

<tbody>
<tr>
<td>3000个</td>
<td>489</td>
<td>224</td>
<td>308</td>
</tr>

<tr>
<td>30000个</td>
<td>2030</td>
<td>331</td>
<td>891</td>
</tr>

<tr>
<td>100000个</td>
<td>6530</td>
<td>689</td>
<td>2247</td>
</tr>

<tr>
<td>300000个</td>
<td>18089</td>
<td>1622</td>
<td>9253</td>
</tr>
</tbody>
</table>

<h4 id="7-3-多线程读取数据测试-span-id-r7-3-span">7.3 多线程读取数据测试 <span id=r7-3></span></h4>

<p>先插入3000条数据类型为4的数据，便于并发测试：</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192437.png" width = 600 /> </div>

<p>然后启动5个线程：</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192454.png" width = 600 /> </div>

<p>查看后台日志：</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20211108192505.png" width = 600 /> </div>

<p>依次按照如下表格的次数进行测试，记录如下：</p>

<table>
<thead>
<tr>
<th>个数</th>
<th>平均耗时</th>
</tr>
</thead>

<tbody>
<tr>
<td>5个</td>
<td>162</td>
</tr>

<tr>
<td>10个</td>
<td>336</td>
</tr>

<tr>
<td>20个</td>
<td>668</td>
</tr>

<tr>
<td>50个</td>
<td>1679</td>
</tr>

<tr>
<td>100个</td>
<td>1399</td>
</tr>

<tr>
<td>200个</td>
<td>1604</td>
</tr>

<tr>
<td>500个</td>
<td>1506</td>
</tr>
</tbody>
</table>

<p>并发测试时，因此同时启动100线程占用时间，一旦线程运行之后，访问redis的时间基本都在1000-2000ms之间。</p>

<h3 id="8-结论-span-id-r8-span">8.结论 <span id=r8></span></h3>

<p>通过读取对比：</p>

<ol>
<li>单次读写，性能最差</li>
<li>jedis性能比RedisTemplate的性能好3倍，并且随着数据量的增大，倍数也成指数增加
因此优先选择jedis，因为他在性能方面完胜RedisTemplate</li>
</ol>

<p>并发测试：</p>

<ol>
<li>并发访问时，对于多线程的开销较大，而对于并发访问redis的性能影响较小。</li>
</ol>
</blockquote>

    </div>
    <footer class="post-footer">
     

     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/springboot-%E5%90%AF%E5%8A%A8%E6%89%A9%E5%B1%95%E7%82%B9/" rel="next" title="">
        <i class="fa fa-chevron-left"></i> 
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/spring%E8%87%AA%E5%B8%A6%E7%9A%84%E7%BA%BF%E7%A8%8B%E6%B1%A0threadpooltaskexecutor/" rel="prev" title="">
         <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>